package com.hclc.entity.model.result;

import com.hclc.entity.model.contans.ApiConst;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * @param <T>
 * @author lixin
 * @version V1.0
 * @ClassName: ResultEntity
 * @Description: TODO(( 返回)
 * @date 2019年5月4日 下午4:42:20
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel
public class ResultEntity<T> implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "状态：{0,成功},{1,失败},{2,Token失效}", required = true, position = 1, example = "0")
    private Integer code;
    @ApiModelProperty(value = "描述：成功或失败等", required = true, position = 2, example = "描述信息")
    private String desc;
    @ApiModelProperty(value = "数据：Json格式数据", required = true, position = 3)
    private T result;

    public ResultEntity() {
        super();
    }

    public ResultEntity(Integer code, String desc) {
        super();
        this.code = code;
        this.desc = desc;
    }

    public ResultEntity(Integer code, String desc, T result) {
        super();
        this.code = code;
        this.desc = desc;
        this.result = result;
    }

    public static <T> ResultEntity<T> ResultSuccess() {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(ApiConst.CODE_SUCC);
        res.setDesc(ApiConst.DESC_SUCC);
        res.setResult(null);
        return res;
    }

    public static <T> ResultEntity<T> ResultSuccess(T result) {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(ApiConst.CODE_SUCC);
        res.setDesc(ApiConst.DESC_SUCC);
        res.setResult(result);
        return res;
    }

    public static <T> ResultEntity<T> ResultSuccess(String desc, T result) {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(ApiConst.CODE_SUCC);
        res.setDesc(desc);
        res.setResult(result);
        return res;
    }

    public static <T> ResultEntity<T> ResultSuccess(Integer code, String desc, T result) {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(code);
        res.setDesc(desc);
        res.setResult(result);
        return res;
    }

    public static <T> ResultEntity<T> ResultFail() {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(ApiConst.CODE_FAIL);
        res.setDesc(ApiConst.DESC_FAIL);
        res.setResult(null);
        return res;
    }

    public static <T> ResultEntity<T> ResultFail(Integer code, String desc) {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(code);
        res.setDesc(desc);
        res.setResult(null);
        return res;
    }

    public static <T> ResultEntity<T> ResultFail(T result) {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(ApiConst.CODE_FAIL);
        res.setDesc(ApiConst.DESC_FAIL);
        res.setResult(result);
        return res;
    }

    public static <T> ResultEntity<T> ResultFail(String desc, T result) {
        ResultEntity<T> res = new ResultEntity<T>();
        res.setCode(ApiConst.CODE_FAIL);
        res.setDesc(desc);
        res.setResult(result);
        return res;
    }


    public boolean success() {
        return code.equals(ApiConst.CODE_SUCC);
    }
}
